/**
 * 
 */
package fr.gfi.agraf.vue.action.administrer.profil;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import fr.gfi.agraf.exception.AgrafException;
import fr.gfi.agraf.service.ICommunService;
import fr.gfi.agraf.utils.PropertiesUtils;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.AbstractApplicationSupportAction;
import fr.gfi.agraf.vue.bean.CommunDTO;
import fr.gfi.agraf.vue.bean.ComposantDTO;
import fr.gfi.agraf.vue.bean.ProfilDTO;

/**
 * @author Zakaria
 * 
 */
public class VoirAdministrerProfilAction extends AbstractApplicationSupportAction {

	/**
	 * Logger
	 */
	private final static Logger LOGGER = Logger.getLogger(VoirAdministrerProfilAction.class);

	/**
	 * 
	 */
	private static final long serialVersionUID = -3650680438059604950L;

	private static final String MESSAGE_POPUP_IMPOSSIBLE_SUPPR_ADMIN = "popup.aide.administrer.profil.admin.impossible.suppr";
	private static final String MESSAGE_POPUP_IMPOSSIBLE_SUPPR_LIE_USER = "popup.aide.administrer.profil.lie.utilisateur";

	private List<ProfilDTO> profilList;

	private List<ComposantDTO> composantList;

	private List<String> listeInfoPage;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * fr.gfi.agraf.vue.action.AbstractApplicationSupportAction#executeAction()
	 */
	@Override
	public String executeAction() throws Exception {
		// Spring, recupere le service commun
		final ICommunService communService = (ICommunService) SpringFactory.getApplicationContext().getBean(
				"CommunService");
		try {
			// fait appel au service commun
			final CommunDTO communDTO = communService.getProfilAndComposant();
			profilList = communDTO.getProfilList();
			composantList = communDTO.getComposantList();
		} catch (final AgrafException ae) {
			// Recupére le message d'erreur
			final String messageErreur = PropertiesUtils.getProperty(ae.getKey());
			// Ajoute action error
			addActionError(messageErreur);
			LOGGER.error(messageErreur, ae);
			return ERROR;
		}

		listeInfoPage = new ArrayList<String>();
		listeInfoPage.add(PropertiesUtils.getProperty(MESSAGE_POPUP_IMPOSSIBLE_SUPPR_ADMIN));
		listeInfoPage.add(PropertiesUtils.getProperty(MESSAGE_POPUP_IMPOSSIBLE_SUPPR_LIE_USER));

		return SUCCESS;
	}

	/**
	 * @return the profilList
	 */
	public List<ProfilDTO> getProfilList() {
		return profilList;
	}

	/**
	 * @param profilList
	 *            the profilList to set
	 */
	public void setProfilList(final List<ProfilDTO> profilList) {
		this.profilList = profilList;
	}

	/**
	 * @return the composantList
	 */
	public List<ComposantDTO> getComposantList() {
		return composantList;
	}

	/**
	 * @param composantList
	 *            the composantList to set
	 */
	public void setComposantList(final List<ComposantDTO> composantList) {
		this.composantList = composantList;
	}

	/**
	 * @return the listeInfoPage
	 */
	public List<String> getListeInfoPage() {
		return listeInfoPage;
	}

}
